package dynamicStudy;

public class MathSubArray {

    /**
     * JZ T42 连续子数组的最大和
     * @param args
     */
    public static void main(String[] args) {

    }

    /**
     * 动态规划的方法，要么选择该值要么不选择
     * @param nums
     * @return
     */
    public int maxSubArray(int[] nums) {
        int maxSum = nums[0];
        int pre = nums[0];
        for (int i = 1; i < nums.length; i++){
            pre = Math.max(pre + nums[i], nums[i]);
            maxSum = Math.max(pre, maxSum);
        }
        return maxSum;
    }
}
